package com.chenfan.mcn.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * @Author liuyang
 * @Date 2021/5/14
 * @Time 16:57
 * @Version V1.0
 **/
@Getter
@AllArgsConstructor
public enum PaybackStatusEnum {
    /**
     * 收入合同回款状态
     */
    NO(0, "未回款"),

    PART(1, "部分回款"),

    ALL(2, "已回款");

    private final Integer code;

    private final String statusName;

    public Integer code() {
        return this.code;
    }

    public static String getStatusName(Integer code) {
        if(Objects.isNull(code)) {
            return null;
        }
        for (PaybackStatusEnum status : PaybackStatusEnum.values()) {
            if (status.code.equals(code)) {
                return status.statusName;
            }
        }
        return null;
    }

    public static boolean isAllPayback(Integer paybackStatus) {
        return PaybackStatusEnum.ALL.code.equals(paybackStatus);
    }

    public static boolean isUnPayback(Integer paybackStatus) {
        return PaybackStatusEnum.NO.code.equals(paybackStatus);
    }

    /** 根据状态码任意匹配
     * @param code
     * @param items
     * @return
     */
    public static boolean anyMatch(Integer code, PaybackStatusEnum... items) {
        boolean match = false;
        if(code != null) {
            for(PaybackStatusEnum item : items) {
                if(item.code() == code.intValue()) {
                    match = true;
                    break;
                }
            }
        }
        return match;
    }
}
